using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Web;
using System.Xml;

namespace Warcraft.Armory
{

    public class WarcraftArmory
    {

        private WarcraftArmoryRegion region;

        public WarcraftArmory()
        {
            region = WarcraftArmoryRegion.Europe;
        }

        public WarcraftArmory(WarcraftArmoryRegion region)
        {
            this.region = region;
        }

        /* Methods */

        public HttpWebResponse Request(string url)
        {
            // Initialize url
            string armoryUrl = "http://{base}/{url}";

            // Replace base placeholder with region domain
            switch(region) {
                case WarcraftArmoryRegion.NorthAmerica: armoryUrl = armoryUrl.Replace("{base}","www.wowarmory.com");
                                                        break;
                case WarcraftArmoryRegion.Europe:       armoryUrl = armoryUrl.Replace("{base}","eu.wowarmory.com");
                                                        break;
                case WarcraftArmoryRegion.Oceana:       armoryUrl = armoryUrl.Replace("{base}","www.wowarmory.com");
                                                        break;
                case WarcraftArmoryRegion.Korea:        armoryUrl = armoryUrl.Replace("{base}","kr.wowarmory.com");
                                                        break;
                case WarcraftArmoryRegion.Taiwan:       armoryUrl = armoryUrl.Replace("{base}","tw.wowarmory.com");
                                                        break;
            }

            // Replace url placeholder with supplied one
            if (url.StartsWith("/")) {
                armoryUrl = armoryUrl.Replace("{url}",url.Substring(1,url.Length - 1));
            } else {
                armoryUrl = armoryUrl.Replace("{url}",url);
            }

            // Create request and set various properties
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(armoryUrl);
            request.Credentials = CredentialCache.DefaultCredentials;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";

            // Dispatch request and return response
            return (HttpWebResponse)request.GetResponse();
        }

        /* Properties */

        public WarcraftArmoryRegion Region
        {
            get {
                return region;
            }
            set {
                region = value;
            }
        }

    }

}
